local LB_U = require "packages.lb_kill_utility.utility"

local skel = fk.CreateSkill {
  name = "lb_zero__qieji",
  tags = { LB_U.LeaderSkill },
}

Fk:loadTranslationTable{
  ["lb_zero__qieji"] = "窃机",
  [":lb_zero__qieji"] = "<b><a href='lb_leader_skill'><font color='red'>领袖技</font></a></b>，" ..
  "每回合限一次，“狡兔屋”的角色使用【杀】时，同势力的一名角色可以重铸三张牌以令之不计入次数限制。",

  ["#lb_zero__qieji-ask"] = "窃机：你可以重铸三张牌令 %src 的 %arg 不计入次数限制",

  ["$lb_zero__qieji1"] = "我会好好招待你的。",
  ["$lb_zero__qieji2"] = "想逃跑？没门！",
}

skel:addEffect(fk.CardUsing, {
  anim_type = "support",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name) and data.card.trueName == "slash" and player:usedSkillTimes(skel.name) == 0
    and LB_U.CompareKingdomWith(target, "lb_zero_jiaotuwu")
  end,
  on_trigger = function(self, event, target, player, data)
    local room = player.room
    for _, to in ipairs(room:getAlivePlayers()) do
      if LB_U.CompareKingdomWith(to, "lb_zero_jiaotuwu") and #to:getCardIds("he") > 2 then
        local cards = room:askToCards(to, {
          min_num = 3,
          max_num = 3,
          skill_name = skel.name,
          include_equip = true,
          cancelable = true,
          prompt = "#lb_zero__qieji-ask:" .. player.id .. "::" .. data.card:toLogString()
        })
        if #cards > 0 then
          event:setCostData(self, { cards = cards, to = to })
          room:useSkill(player, self, function()
            self:use(event, target, player, data)
          end, event.skill_data)
          break
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    player.room:recastCard(event:getCostData(self).cards, event:getCostData(self).to, skel.name)
    if not data.extraUse then
      target:addCardUseHistory(data.card.trueName, -1)
      data.extraUse = true
    end
  end,
})

return skel
